﻿using System;
using System.Threading;
using Zeus.Thunder.Core;

namespace SharpTrainer.Threads
{
    class CreateThreadTest : ITestCase
    {
        public void Run()
        {
            Console.WriteLine("Main thread: starting a dedicated thread " +
                                "to do an asynchronous operation");

            Thread dedicatedThread = new Thread(ComputeBoundOp);
            dedicatedThread.Start(5);

            Console.WriteLine("Main thread: Doing other work here...");
            Thread.Sleep(10000);     // Simulating other work (10 seconds)

            dedicatedThread.Join();  // Wait for thread to terminate
            Console.ReadLine();
        }

        // This method's signature must match the ParametizedThreadStart delegate
        private void ComputeBoundOp(Object state)
        {
            // This method is executed by a thread pool thread

            Console.WriteLine("In ComputeBoundOp: state={0}", state);
            Thread.Sleep(1000);  // Simulates other work (1 second)

            // When this method returns, the dedicated thread dies
        }
    }
}

